
#ifndef _SWARMIO_H
#  define _SWARMIO_H

#  include <hash.h>
#  include <swarm.h>
#  include <string.h>

/* Data structures. */

typedef struct _swio_sym_data {

  void *data;
  int type;

} swio_sym_data;

#  define SYM_NUMERIC 1
#  define SYM_STRING  0

typedef char   swio_symbol;
typedef hash_t swio_symbol_table;

typedef struct _swio_file_frame {

  struct _swio_file_frame *prev;
  FILE *file;
  char *name;
  unsigned int current_line;

} swio_file_frame;

typedef struct _swio_file_stack {

  swio_file_frame *top;
  int length;

} swio_file_stack;

typedef struct _swio_insect_desc {

  char *type;

  sw_xmm_vec loc;
  sw_xmm_vec vel;

  sw_size_t f_len_r;  // Length of frespond list
  sw_force **frespond;
  sw_size_t f_len_e;  // Length of femit list
  sw_force **femit;

  char *color;

  int quantity;

} swio_insect_desc;

extern swio_symbol_table *sym_tbl;
extern swio_file_stack   *files;

/* Functions for i/o. */
void              swio_init();
void              swio_sym_add(char *, swio_sym_data *);
swio_sym_data    *swio_sym_get(char *);
swio_sym_data    *swio_sym_set(char *, swio_sym_data *);
swio_sym_data    *swio_sym_make(char *, int);
int               swio_symbolize(char *);
void              swio_undefined_symbol(char *);
void              swio_die_miss_matched_quote(char *);
void             _swio_file_stack_push(swio_file_frame *);
void             _swio_file_stack_pop();
swio_file_frame *_swio_make_file_frame(char *);
inline int       _swio_is_symbol(char *);
void             _swio_print_sym_table();
char            *_swio_trim_quotes(char *);
int              _swio_parse_numeric(char *, double *);
int              _swio_parse_string(char *, char **);
int              _swio_parse_colon_sep_symbols(char *, double *);
int               swio_desc_add_rforce(swio_insect_desc *, char *, sw_swarm *);
int               swio_desc_add_eforce(swio_insect_desc *, char *, sw_swarm *);
void              swio_desc_to_insects(swio_insect_desc *, sw_swarm *);

/* Command parsing functions. */
int               swio_com_include(char *);
int               swio_com_sim_name(char *, sw_swarm *);
int               swio_com_window(char *, sw_swarm *);
int               swio_com_force(char *, sw_swarm *);
int               swio_com_insect(char *, sw_swarm *);
int               swio_com_random(char *);

/* Some preprocesser decs that are useful. */

#  define ATTR_ORIGIN     0
#  define ATTR_SIZE       1
#  define ATTR_NAME       2
#  define ATTR_ORDER      3
#  define ATTR_MAGNITUDE  4
#  define ATTR_TYPE       5
#  define ATTR_FEMIT      6
#  define ATTR_FRESPOND   7
#  define ATTR_LOC        8
#  define ATTR_VEL        9
#  define ATTR_QUANTITY   10
#  define ATTR_COLOR      11
#  define ATTR_MIN        12
#  define ATTR_MAX        13
#  define NUM_ATTRS       14

#endif
